package com.isman.placeslist;


import com.isman.placeslist.apiobject.SingUp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class PageConfirm extends Activity {
	public static final String SINGUP_INFO = "SingupInfo";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.page_comfirm);	
		setTitle("Confirm Password");
		
		singup = (SingUp)getIntent().getSerializableExtra(SINGUP_INFO);
		
		vEtPass = (EditText)findViewById(R.id.et_cf_password);
		vEtConfirmPass = (EditText)findViewById(R.id.et_cf_confirm_password);
		vlblEmail = (TextView)findViewById(R.id.lbl_cf_email);
		vBtnSingup = (Button)findViewById(R.id.btn_cf_singup);
		
		vlblEmail.setText(singup.getEmail());
		vBtnSingup.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(vEtPass.getText().toString().length() > 6 && vEtConfirmPass.getText().toString().trim().equals(vEtPass.getText().toString().trim())){
					singup.setPassword(vEtPass.getText().toString().trim());
					Singup();
				}else{
					Toast.makeText(PageConfirm.this, "Password Incorrect", Toast.LENGTH_LONG).show();
				}
			}
		});
	}
	protected void Singup(){
		switch (singup.getFromWith()) {
		case SingUp.FROM_WITH_EMAIL:
			Intent intent = new Intent();
			intent.putExtra(SINGUP_INFO, singup);
			setResult(RESULT_OK, intent);
			finish();
			break;
		case SingUp.FROM_WITH_FB:
			Intent intent1 = new Intent();
			intent1.putExtra(SINGUP_INFO, singup);
			setResult(RESULT_OK, intent1);
			finish();
			break;
		}
	}
	private SingUp singup;
	private TextView vlblEmail;
	private EditText vEtPass,vEtConfirmPass;
	private Button vBtnSingup;
}
